﻿using System;
using Kugar.MVC.MobileUI.WeUI.Enum;
using Kugar.MVC.MobileUI.WeUI.PageControls.PageCommons;
using Kugar.MVC.MobileUI.WeUI.PageControls.PageForm;

#if !NETCOREAPP
using System.Web;
using System.Web.Mvc;
using System.Web.WebPages;
#endif

#if NETCOREAPP
using Microsoft.AspNetCore.Mvc.Rendering;
#endif


namespace Kugar.MVC.MobileUI.WeUI.Helpers.Forms
{
    public static class FormHelper
    {
        /// <summary>
        /// 添加一个下拉框
        /// </summary>
        /// <param name="frm"></param>
        /// <returns></returns>
        public static PageForm_Selector AddSelector(this PageForm_Form frm)
        {
            return new PageForm_Selector(frm.ViewContext);
        }

        /// <summary>
        /// 添加一个Textarea框
        /// </summary>
        /// <param name="frm"></param>
        /// <returns></returns>
        public static PageForm_Textarea AddTextarea(this PageForm_Form frm)
        {
            return new PageForm_Textarea(frm.ViewContext);
        }

        public static PageForm_TextareaInLine AddTextareaInLine(this PageForm_Form frm)
        {
            return new PageForm_TextareaInLine(frm.ViewContext);
        }


        /// <summary>
        /// 添加一个Label框
        /// </summary>
        /// <param name="frm"></param>
        /// <returns></returns>
        public static PageForm_Label AddLabel(this PageForm_Form frm)
        {
            return new PageForm_Label(frm.ViewContext);
        }

        /// <summary>
        /// 添加一个文本框
        /// </summary>
        /// <param name="frm"></param>
        /// <returns></returns>
        public static PageForm_TextBox AddTextBox(this PageForm_Form frm)
        {
            return new PageForm_TextBox(frm.ViewContext);
        }

        /// <summary>
        /// 添加一个复选框列表字段
        /// </summary>
        /// <param name="frm"></param>
        /// <returns></returns>
        public static PageForm_CheckBoxList AddCheckBoxList(this PageForm_Form frm)
        {
            return new PageForm_CheckBoxList(frm.ViewContext);
        }

        /// <summary>
        /// 添加一个单选列表字段
        /// </summary>
        /// <param name="frm"></param>
        /// <returns></returns>
        public static PageForm_Radio AddRadioList(this PageForm_Form frm)
        {
            return new PageForm_Radio(frm.ViewContext);
        }

        /// <summary>
        /// 添加一个单选开关字段
        /// </summary>
        /// <param name="frm"></param>
        /// <returns></returns>
        public static PageForm_Switch AddSwitchButton(this PageForm_Form frm)
        {
            return new PageForm_Switch(frm.ViewContext);
        }

        /// <summary>
        /// 添加一个验证码输入框
        /// </summary>
        /// <param name="frm"></param>
        /// <returns></returns>
        public static PageForm_VCode AddVCode(this PageForm_Form frm)
        {
            return new PageForm_VCode(frm.ViewContext);
        }

        /// <summary>
        /// 添加一个手机验证码输入框和按钮
        /// </summary>
        /// <param name="frm"></param>
        /// <returns></returns>
        public static PageForm_MobileVCode AddMobileVCode(this PageForm_Form frm)
        {
            return new PageForm_MobileVCode(frm.ViewContext);
        }

        /// <summary>
        /// 添加一个带下拉框的文本框,,可用于选择账号类型,选择区号等等
        /// </summary>
        /// <param name="frm"></param>
        /// <returns></returns>
        public static PageForm_TextBoxWithSelector AddTextBoxWithSelector(this PageForm_Form frm)
        {
            return new PageForm_TextBoxWithSelector(frm.ViewContext);
        }

        /// <summary>
        /// 添加一个计数器字段(左右加减按钮和中间一个文本框)
        /// </summary>
        /// <param name="frm"></param>
        /// <returns></returns>
        public static PageForm_Counter AddCounter(this PageForm_Form frm)
        {
            return new PageForm_Counter(frm.ViewContext);
        }

        /// <summary>
        /// 添加一个时间/时间日期选择器
        /// </summary>
        /// <param name="frm"></param>
        /// <returns></returns>
        public static PageForm_DatePicker AddDatePicker(this PageForm_Form frm)
        {
            return new PageForm_DatePicker(frm.ViewContext);
        }

        /// <summary>
        /// 添加一个省市区选择框
        /// </summary>
        /// <param name="frm"></param>
        /// <returns></returns>
        public static PageForm_CitySelector AddCitySelector(this PageForm_Form frm)
        {
            return new PageForm_CitySelector(frm.ViewContext);
        }

        /// <summary>
        /// 添加一个按钮区域
        /// </summary>
        /// <param name="frm"></param>
        /// <returns></returns>
        public static PageForm_ButtonArea AddButtonArea(this PageForm_Form frm)
        {
            return new PageForm_ButtonArea(frm.ViewContext);
        }

        /// <summary>
        /// 添加一个单个的图片上传字段,可点击上传,需返回ResultReturn类型的json数据
        /// </summary>
        /// <param name="frm"></param>
        /// <returns></returns>
        public static PageForm_SingleImage AddSingleImage(this PageForm_Form frm)
        {
            return new PageForm_SingleImage(frm.ViewContext);
        }

        /// <summary>
        /// 多图上传的表单字段
        /// </summary>
        /// <param name="frm"></param>
        /// <returns></returns>
        public static PageForm_MultiImage AddMultiImage(this PageForm_Form frm)
        {
            return new PageForm_MultiImage(frm.ViewContext);
        }

        /// <summary>
        /// 添加一个左滑显示按钮的外框字段,可直接对InnerField属性赋值字段控件
        /// </summary>
        /// <param name="frm"></param>
        /// <returns></returns>
        public static PageForm_Swipeout AddSwipeout(this PageForm_Form frm)
        {
            return new PageForm_Swipeout(frm.ViewContext);
        }

        /// <summary>
        /// 添加一个左滑显示按钮的容器字段
        /// </summary>
        /// <param name="frm"></param>
        /// <returns></returns>
        public static PageForm_SwipeoutContainer AddSwipeoutContainer(this PageForm_Form frm)
        {
            return new PageForm_SwipeoutContainer(frm.ViewContext);
        }

        /// <summary>
        /// 添加一个自定义单元格
        /// </summary>
        /// <returns></returns>
        public static PageCommon_Cell AddCustomCell()
        {
            return null;

        }

        /// <summary>
        /// 添加一个跳转链接样式的表单控件
        /// </summary>
        /// <param name="frm"></param>
        /// <returns></returns>
        public static PageForm_Link AddLink(this PageForm_Form frm)
        {
            return new PageForm_Link(frm.ViewContext);
        }

        public static TFormField Label<TFormField>(this TFormField field, string label) where TFormField : PageForm_FieldBase
        {
            field._label = label;

            return field;
        }

        public static TFormField Name<TFormField>(this TFormField field, string name) where TFormField : PageForm_FieldBase
        {
            field._name = name;

            return field;
        }

        //public static TFormField AddSwipeButton<TFormField>(this TFormField form, Action<SwipeButton> config) where TFormField : PageForm_CellForField
        //{
        //    var cof = new SwipeButton();

        //    config(cof);

        //    form._swipeLst.Value.Add(cof);
            
        //    form._swiped = true;

        //    return form;
        //}

        public static TFormField Tips<TFormField>(this TFormField field, string tips) where TFormField : PageForm_FieldBase
        {
            field._tip = tips;

            return field;
        }

        public static TFormField WithLink<TFormField>(this TFormField field, Action<ButtonItemBase> configFunc) where TFormField : PageForm_FieldBase
        {
            var config=new ButtonItemBase();
            config.Class("weui-cell weui-cell_link");
            config.Type(ButtonTypeEnum.Link);
            config.ButtonStyle(ButtonStyleType.Link);
            configFunc(config);

            field._moreBtn = config;

            return field;
        }

        //public static TForm Title<TForm>(this TForm form, string title) where TForm : PageForm_CellForField
        //{
        //    form._title = title;

        //    return this;
        //}
    }
}